package xxxx.utility;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.lang.reflect.Type;

/**
 * Created by liwei.b on 2016/12/6.
 */
public class JsonUtility {
    private static Gson gson;

    private JsonUtility() {
    }

    static {
        gson = new Gson();
    }

    public static String toJson(Object value) {
        return gson.toJson(value);
    }

    public static <T> T fromJson(String jsonString, Type type) {
        try {
            return gson.fromJson(jsonString, type);
        } catch (Exception ex) {
            System.out.println("JsonUtility.fromJson().error." + ex.toString());
        }
        return null;
    }
}
